package com.example.httpmessageconvert.httpmessageconvert.messageconfig;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * @author 奶茶
 * Created by on 2018/1/2.
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    /**
     * 这是自定义消息的转换器
     * configureMessageConverters 重载会覆盖掉 springMvc 默认注册的多个 HttpMessageConverter
     * extendMessageConverters 仅添加一个自定义的HttpMessageConverter,不覆盖默认注册的HttpMessageConverter
     * @param converters
     */
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters){
        converters.add(new JsonConvert());
        super.extendMessageConverters(converters);
    }

    /**
     * 自定义枚举绑定
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry){
        registry.addConverterFactory(new EnumConfig());
    }

}
